import 'package:flutter/material.dart';
import 'package:flutter_project/config/app_bar_view.dart';


class VideoLikesSetPage extends StatefulWidget {
  const VideoLikesSetPage({super.key});

  @override
  State<VideoLikesSetPage> createState() => _VideoLikesSetPageState();
}

class _VideoLikesSetPageState extends State<VideoLikesSetPage> {
  final Color manBgColor = const Color.fromRGBO(236, 242, 254, 1.0);
  final Color manTextColor = const Color.fromRGBO(99, 141, 179, 1.0);

  final Color womanBgColor = const Color.fromRGBO(244, 239, 234, 1.0);
  final Color womanTextColor = const Color.fromRGBO(210, 118, 96, 1.0);

  bool isMan = true;
  bool isWoMan = false;

  @override
  Widget build(BuildContext context) {
    return CommonAppWidget.navAppBar(
        title: '偏好',
        bgColor: Colors.white,
        rightActions: [
          TextButton(
            onPressed: () {
              debugPrint('点击了保存');
            },
            child: const Text(
              '保存',
            ),
          )
        ],
        childWidget: ListView(
          padding: const EdgeInsets.only(left: 20, top: 20),
          children: [
            const Text(
              '选择类型\n为你推荐更优质内容',
              style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
            ),
            GestureDetector(
              onTap: () {
                if (isMan) {
                  return;
                }
                setState(() {
                  isMan = true;
                  isWoMan = false;
                });
              },
              child: getRotateWidget(
                childWidget: EggShape(
                  fillColor: isMan ? manTextColor : manBgColor,
                  textColor: isMan ? manBgColor : manTextColor,
                ),
              ),
            ),
            GestureDetector(
              onTap: () {
                if (isWoMan) {
                  return;
                }
                setState(() {
                  isMan = false;
                  isWoMan = true;
                });
              },
              child: getRotateWidget(
                childWidget: EggShape(
                  fillColor: isWoMan ? womanTextColor : womanBgColor,
                  textColor: isWoMan ? womanBgColor : womanTextColor,
                  name: '女生',
                ),
              ),
            ),
          ],
        ));
  }

  Widget getRotateWidget({required Widget childWidget}) {
    return Transform.rotate(
      angle: -0.2,
      child: childWidget,
    );
  }
}

class EggShape extends StatelessWidget {
  final Color? fillColor;
  final Color? textColor;
  final String name;

  const EggShape({this.fillColor, this.textColor, this.name = '男生', super.key});

  @override
  Widget build(BuildContext context) {
    return CustomPaint(
      isComplex: true,
      painter: EggShapePainter(fillColor: fillColor),
      child: Container(
        alignment: Alignment.center,
        height: 200,
        width: 300,
        child: Text(
          '我是$name',
          style: TextStyle(
              color: textColor, fontSize: 18, fontWeight: FontWeight.w600),
        ),
      ),
    );
  }
}

class EggShapePainter extends CustomPainter {
  final Color? fillColor;

  const EggShapePainter({this.fillColor});

  @override
  void paint(Canvas canvas, Size size) {
    final Paint paint = Paint()
      ..color = fillColor ?? Colors.blue
      ..style = PaintingStyle.fill;

    final double width = size.width;
    final double height = size.height;

    // 计算鸡蛋形状的椭圆参数
    final double centerX = width / 2;
    final double centerY = height / 2;
    final double xRadius = width / 2;
    final double yRadius = height / 2;

    // 绘制椭圆形
    canvas.drawOval(
        Rect.fromCenter(
            center: Offset(centerX, centerY), width: xRadius, height: yRadius),
        paint);
  }

  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) {
    return false;
  }
}
